package logic

import (
	"context"
	"ewaimai/waimairpc/internal/svc"
	"ewaimai/waimairpc/models"
	"ewaimai/waimairpc/waimairpc"
	"github.com/zeromicro/go-zero/core/logx"
)

type OrderAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderAddLogic {
	return &OrderAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderAddLogic) OrderAdd(in *waimairpc.OrderAddRequest) (*waimairpc.OrderAddResponse, error) {
	// todo: add your logic here and delete this line
	var err error

	var o models.Order
	o.OrderNo = in.OrderNo
	o.UserId = int(in.UserId)
	o.Jiedan = in.Jiedan
	o.Xiadan = in.Xiadan
	o.Pay = in.Pay
	o.Peisong = in.Peisong
	//totam := float64(in.Num) * g.Price
	o.Finish = in.Finish
	if err = o.CreateOrder(); err != nil {
		logx.Error("订单添加失败")
	}
	//alipay, _ := pkg.NewAlipay()
	//Payurl, _ := alipay.Alipay(o.OrderNo, fmt.Sprintf("%.2f", totam))
	return &waimairpc.OrderAddResponse{
		Id: int64(o.ID),
		//	PayUrl: Payurl,
	}, nil
}
